package com.hpli.domain.credit.model.aggregate;


import com.hpli.domain.award.model.valobj.TaskStateVO;
import com.hpli.domain.credit.event.CreditAdjustSuccessMessageEvent;
import com.hpli.domain.credit.model.entity.CreditAccountEntity;
import com.hpli.domain.credit.model.entity.CreditOrderEntity;
import com.hpli.domain.credit.model.entity.TaskEntity;
import com.hpli.domain.credit.model.valobj.TradeNameVO;
import com.hpli.domain.credit.model.valobj.TradeTypeVO;
import com.hpli.types.event.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

import java.math.BigDecimal;

/**
 * @Author: 汀
 * @CreateTime: 2025-04-22
 * @Description: 交易聚合对象
 * @Version: 1.0
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class TradeAggregate {

    /**
     * 用户Id
     */
    private String userId;

    /**
     * 积分账户实体
     */
    private CreditAccountEntity creditAccountEntity;

    /**
     * 积分订单实体
     */
    private CreditOrderEntity creditOrderEntity;

    private TaskEntity taskEntity;

    public static CreditAccountEntity createCreditAccountEntity(String userId, BigDecimal adjustAmount) {
        return CreditAccountEntity.builder()
                .userId(userId)
                .adjustAmount(adjustAmount)
                .build();
    }

    public static CreditOrderEntity createCreditOrderEntity(String userId, TradeNameVO tradeName, TradeTypeVO tradeType, BigDecimal tradeAmount, String outBusinessNo) {
        return CreditOrderEntity.builder()
                .userId(userId)
                .orderId(RandomStringUtils.randomNumeric(12))
                .tradeName(tradeName)
                .tradeType(tradeType)
                .tradeAmount(tradeAmount)
                .outBusinessNo(outBusinessNo)
                .build();
    }

    public static TaskEntity createTaskEntity(String userId, String topic, String messageId,
                                              BaseEvent.EventMessage<CreditAdjustSuccessMessageEvent.CreditAdjustSuccessMessage> message, String outBusinessNo) {
        return TaskEntity.builder()
                .userId(userId)
                .topic(topic)
                .messageId(messageId)
                .message(message)
                .state(TaskStateVO.create)
                .build();
    }

}
